package com.btl.service.ai.biz.adaptor;

import com.btl.boot.core.dto.response.R;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import dev.langchain4j.model.output.structured.Description;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Tim
 * @since 2025-07-22
 */
@Controller
@RequestMapping("/kwKnowledge")
public class KwKnowledgeController {


    private static final List<Map<String, Object>> TEST_MAP = new ArrayList<>();

    @GetMapping("test")
    @Tool("测试样本")
    public R<String> test(@RequestParam("name") @P("测试的设备名称") String name, @RequestParam("num") @P("测试的样本数量") Integer num) {
        System.out.println(name + "-" + num);
        return R.ok("测试成功");
    }

    @GetMapping("notice")
    @Tool("添加提醒")
    public R<String> notice(
            @RequestParam("date") @P("提醒日期") LocalDate date,
            @RequestParam("dateTime") @P("提醒时间") LocalDateTime dateTime,
            @RequestParam("event") @P("提醒内容") String event) {
        System.out.println(date + "\n" + dateTime + "\n" + event);
        TEST_MAP.add(Map.of("key", UUID.randomUUID()
                .toString(), "date", date, "dateTime", dateTime, "event", event));
        return R.ok("添加成功");

    }

    @Tool("已添加的提醒记录，取消提醒前调用")
    public R<List<Map<String, Object>>> listNotice() {
        return R.ok(TEST_MAP);
    }


    @Tool("取消提醒,如果没有记录，提示没有可取消的任务")
    public R<String> cancelNotice(@P("取消提醒的 key") String key) {
        TEST_MAP.removeIf(map -> map.get("key").equals(key));
        return R.ok("取消成功");
    }

    @Tool("当前日期时间")
    public R<LocalDateTime> currentDateTime() {
        return R.ok(LocalDateTime.now());
    }
}
